package com.itheima.controller;

import com.itheima.common.R;
import com.itheima.domain.HomeRecommendSubject;
import com.itheima.manager.SmsHomeRecommendSubjectManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class SmsHomeRecommendSubjectController {

    @Autowired
    SmsHomeRecommendSubjectManager smsHomeRecommendSubjectManager;

    //专题推荐分页查询
    @GetMapping("/home/recommendSubject/list")
    public R findByPage(@RequestParam(defaultValue = "1",required = false)Integer pageNum,
                        @RequestParam(defaultValue = "10",required = false)Integer pageSize,
                        @RequestParam(required = false)String subjectName,
                        @RequestParam(required = false)Integer recommendStatus)
    {
      return   smsHomeRecommendSubjectManager.findByPage(pageNum,pageSize,subjectName,recommendStatus);
    }


    //添加首页推荐
    @PostMapping("/home/recommendSubject/create")
    public R addNew(@RequestBody HomeRecommendSubject homeRecommendSubject)
    {
        return smsHomeRecommendSubjectManager.addNew(homeRecommendSubject);

    }


    //批量删除
    @PostMapping("/home/recommendSubject/delete")
    public R delete(Integer [] ids)
    {
        return smsHomeRecommendSubjectManager.delete(ids);

    }

    //批量修改推荐状态
    @PostMapping("/home/recommendSubject/update/recommendStatus")
    public R update(Integer [] ids,Integer recommendStatus)
    {
        return smsHomeRecommendSubjectManager.update(ids,recommendStatus);

    }

    //修改推荐排序
    @PostMapping("/home/recommendSubject/update/sort/{id}")
    public R sort(@PathVariable Integer id,@RequestParam(required = false) Integer sort)
    {
        return smsHomeRecommendSubjectManager.sort(id,sort);
    }
}
